﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;

namespace UnitTestUtils.UI.Automation
{
    /// <summary>
    /// Profides commonly used functionality around UIAutomation properties.
    /// </summary>
    public class ConditionHelper
    {
        /// <summary>
        /// Returns a <see cref="Condition"/> instance to filter for controls with a given automationID.
        /// </summary>
        /// <param name="automationID"></param>
        /// <returns></returns>
        public static Condition ByAutomationID(string automationID)
        {
            var c0 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
            var c1 = new PropertyCondition(AutomationElement.AutomationIdProperty, automationID);
            return new AndCondition(c0, c1);
        }

        /// <summary>
        /// Returns a <see cref="Condition"/> instance to filter for controls with a given ControlType.
        /// </summary>
        /// <param name="controlType"></param>
        /// <returns></returns>
        public static Condition ByControlType(ControlType controlType)
        {
            var c0 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
            var c1 = new PropertyCondition(AutomationElement.ControlTypeProperty, controlType);
            return new AndCondition(c0, c1);
        }

        /// <summary>
        /// Returns a <see cref="Condition"/> instance to filter for controls with a given control name.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Condition ByName(string name)
        {
            var c0 = new PropertyCondition(AutomationElement.IsControlElementProperty, true);
            var c1 = new PropertyCondition(AutomationElement.NameProperty, name);
            return new AndCondition(c0, c1);
        }
    }
}
